package com.example.boot.rabbitmq.producer.boot.rest;


import com.example.boot.rabbitmq.producer.boot.config.delay.RabbitDelayProperties;
import com.example.boot.rabbitmq.producer.boot.config.direct.RabbitDirectProperties;
import com.example.boot.rabbitmq.producer.boot.config.fanout.RabbitFanoutProperties;
import com.example.boot.rabbitmq.producer.boot.config.topic.RabbitTopicProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * rabbit不同类型exchange 演示
 * @author root
 * @date 2021-03-09 12:08
 */
@RestController
@RequiredArgsConstructor
public class RabbitBootRest {

    private final RabbitTemplate rabbitTemplate;
    private final RabbitDirectProperties rabbitDirectProperties;
    private final RabbitTopicProperties rabbitTopicProperties;
    private final RabbitFanoutProperties rabbitFanoutProperties;
    private final RabbitDelayProperties rabbitDelayProperties;

    /**
     * direct 类型生产者
     * @return 结果
     */
    @GetMapping("direct")
    public String direct() {
        rabbitTemplate.convertAndSend(rabbitDirectProperties.getDirectExchange(), rabbitDirectProperties.getDirectKey(), "direct message");
        return "ok";
    }


    /**
     * topic 类型生产者
     * @return 结果
     */
    @GetMapping("topic")
    public String topic() {
        rabbitTemplate.convertAndSend(rabbitTopicProperties.getTopicExchange(), rabbitTopicProperties.getTopicKey(), "topic message");
        return "ok";
    }

    /**
     * fanout 类型生产者
     * @return 结果
     */
    @GetMapping("fanout")
    public String fanout() {
        rabbitTemplate.convertAndSend(rabbitFanoutProperties.getFanoutExchange(), "", "fanout message");
        return "ok";
    }


    /**
     * delay 类型生产者
     * @return 结果
     */
    @GetMapping("delay")
    public String delay() {
        rabbitTemplate.convertAndSend(rabbitDelayProperties.getNormalExchange(), rabbitDelayProperties.getDelayKey(), "delay message");
        return "ok";
    }


}
